var express=require('express'),
<<<<<<< HEAD
    bodyParser=require('body-parser'),
    path=require('path'),
    config=require('./config/config.js'),
    session = require("express-session"),
    MongoStore = require("connect-mongo")(session),
    zhens=require('./models/zhenshi'),
    mimis=require('./models/mimi');
=======
<<<<<<< HEAD
    config=require('./config/config.js'),
    bodyParser=require('body-parser'),
    path=require('path'),
    zhens=require('./models/zhenshi'),
    chuangs=require('./models/chuangzuo'),
    mimis=require('./models/mimi');



=======
    bodyParser=require('body-parser'),
    path=require('path'),
    config=require('./config/config.js'),
    zhens=require('./models/zhenshi');
>>>>>>> 8714c8b5ba9feaa1406e84e2f3dad3ba2d6fab1d

/*
 定义常量,或用config
 const  Port=3000;
 const  Host='localhost';
 */

//创建express项目
<<<<<<< HEAD
=======
>>>>>>> bdfec7a59cf26d8104ee7ff70bd38d4151c093b1
>>>>>>> 8714c8b5ba9feaa1406e84e2f3dad3ba2d6fab1d
var app=express();
    config=require('./config/config.js'),
    bodyParser=require('body-parser'),
    path=require('path'),
    zhens=require('./models/zhenshi'),
    chuangs=require('./models/chuangzuo'),
    mimis=require('./models/mimi');

<<<<<<< HEAD
var users = require('./routers/user');


app.use(session({
    secret: 'mobile', // 用来注册session id 到cookie中，相当与一个密钥
    name: 'mobile', // cookie的name
    resave: false,
    saveUninitialized: true,
    store: new MongoStore({
        url: 'mongodb://192.168.40.91:27017/XiNiu',
        autoRemove: 'native'
    })
}));

//指定静态资源目录，如 images，css，js
=======
>>>>>>> 8714c8b5ba9feaa1406e84e2f3dad3ba2d6fab1d


<<<<<<< HEAD
app.use(express.static(path.join(__dirname,'static')));
<<<<<<< HEAD

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));      //传来的数据是多维的就用true

app.use('/users', users);

app.use(function (req, res) {
    res.status(404).json({msg: '404 Not Found'});
});


//真事接口
app.get('/api/zhenshilianjie/get', function (req, res) {
=======
app.use(bodyParser.urlencoded({extended:true}));



//首页
function data1(callback) {
=======
var app=express();



 /*处理404*/
//首页
function dataIndex(callback) {
    var http=require('http');
    http.get("http://www.xiniugushi.com/function/story.inc.php?action=feedlist", function(res){
        var size = 0;
        var chunks = [];
        res.on('data', function(chunk){
            size += chunk.length;
            chunks.push(chunk);
        });
        res.on('end', function(){
            var data = JSON.parse(Buffer.concat(chunks, size).toString());
            callback(data)
        });
    }).on('error', function(e) {
        console.log("Got error: " + e.message);
    });
}

//推荐
function dataDiscover(callback) {
>>>>>>> bdfec7a59cf26d8104ee7ff70bd38d4151c093b1
    var http=require('http');
    http.get("http://www.xiniugushi.com/function/story.inc.php?action=feedlist", function(res){
        var size = 0;
        var chunks = [];
        res.on('data', function(chunk){
            size += chunk.length;
            chunks.push(chunk);
        });
        res.on('end', function(){
            var data = JSON.parse(Buffer.concat(chunks, size).toString());
            callback(data)
        });
    }).on('error', function(e) {
        console.log("Got error: " + e.message);
    });
}
<<<<<<< HEAD
=======
//推荐接口
app.get('/api/discover/get', function (req, res) {
    function callback(doc) {
        res.status(200).json({success: true, message: '', data: doc});
    }
    dataDiscover(callback);
});
//首页接口
>>>>>>> bdfec7a59cf26d8104ee7ff70bd38d4151c093b1
app.get('/api/shouye/get', function (req, res) {
    function callback(doc) {
        res.status(200).json({success: true, message: '', data: doc});
    }
<<<<<<< HEAD
    data1(callback);
});
=======
    dataIndex(callback);
});
app.get('/a', function(req, res){
    res.send("aaa");
});

>>>>>>> bdfec7a59cf26d8104ee7ff70bd38d4151c093b1



//真事接口
app.get('/api/zhenshi/get', function (req, res) {
>>>>>>> 8714c8b5ba9feaa1406e84e2f3dad3ba2d6fab1d
    var findCon = req.query || {};
    function callback(doc) {
        res.status(200).json({success: true, message: '', data: doc});
        //console.log(doc.data)
    }
    zhens.zhenshilianjie(findCon,callback);
});
<<<<<<< HEAD
/*使用中间处理body参数

 三种传参方式：？ / body
 1、index.html?id=1
 2、www.baidu.com/a/

 form-data
 a=1&b=2
 {a:1;b:2}

 处理404*/

//首页
=======
<<<<<<< HEAD
//创作接口
app.get('/api/chuangzuo/get', function (req, res) {
=======
/*使用中间处理body参数

app.use(express.static(path.join(__dirname,'static')));
app.use(bodyParser.urlencoded({extended:true}));
 处理404*/

//
>>>>>>> 8714c8b5ba9feaa1406e84e2f3dad3ba2d6fab1d
function data1(callback) {
    var http=require('http');
    http.get("http://www.xiniugushi.com/function/story.inc.php?action=feedlist", function(res){
        var size = 0;
        var chunks = [];
        res.on('data', function(chunk){
            size += chunk.length;
            chunks.push(chunk);
        });
        res.on('end', function(){
            var data = JSON.parse(Buffer.concat(chunks, size).toString());
            callback(data)
        });
    }).on('error', function(e) {
        console.log("Got error: " + e.message);
    });
}
app.get('/api/shouye/get', function (req, res) {
    function callback(doc) {
        res.status(200).json({success: true, message: '', data: doc});
    }
    data1(callback);
});



<<<<<<< HEAD
//真事接口
=======
//���½ӿ�
>>>>>>> 8714c8b5ba9feaa1406e84e2f3dad3ba2d6fab1d
app.get('/api/zhenshi/get', function (req, res) {
>>>>>>> bdfec7a59cf26d8104ee7ff70bd38d4151c093b1
    var findCon = req.query || {};
    function callback(doc) {
        res.status(200).json({success: true, message: '', data: doc});
        //console.log(doc.data)
    }
    chuangs.chuangzuowenzhang(findCon,callback);
});
<<<<<<< HEAD


//密码接口
app.get('/api/mimi/get', function (req, res) {
=======
//�����ӿ�
app.get('/api/chuangzuo/get', function (req, res) {
>>>>>>> bdfec7a59cf26d8104ee7ff70bd38d4151c093b1
    var findCon = req.query || {};
    function callback(doc) {
        res.status(200).json({success: true, message: '', data: doc});
        //console.log(doc.data)
    }
<<<<<<< HEAD
    mimis.mimi(findCon,callback);
});
/*使用中间处理body参数

 三种传参方式：？ / body
 1、index.html?id=1
 2、www.baidu.com/a/
=======
    chuangs.chuangzuowenzhang(findCon,callback);
});
<<<<<<< HEAD
//秘密接口
=======


//����ӿ�
>>>>>>> 8714c8b5ba9feaa1406e84e2f3dad3ba2d6fab1d
app.get('/api/mimi/get', function (req, res) {
    var findCon = req.query || {};
    function callback(doc) {
        res.status(200).json({success: true, message: '', data: doc});
        //console.log(doc.data)
    }
    mimis.mimi(findCon,callback);
});
<<<<<<< HEAD
/*使用中间处理body参数

 三种传参方式：？ / body
 1、index.html?id=1
 2、www.baidu.com/a/
=======
/*ʹ���м䴦��body����

 ���ִ��η�ʽ���� / body
 1��index.html?id=1
 2��www.baidu.com/a/
>>>>>>> bdfec7a59cf26d8104ee7ff70bd38d4151c093b1
>>>>>>> 8714c8b5ba9feaa1406e84e2f3dad3ba2d6fab1d

 form-data
 a=1&b=2
 {a:1;b:2}

<<<<<<< HEAD
 处理404*/
=======
<<<<<<< HEAD
 处理404*/
=======
 ����404*/

>>>>>>> bdfec7a59cf26d8104ee7ff70bd38d4151c093b1
>>>>>>> 8714c8b5ba9feaa1406e84e2f3dad3ba2d6fab1d
app.listen(config.port,config.host,function(err){
    if(err)
        console.log(err);
    console.log("port is start")
});
